package com.chinairi.mall.service.impl;

import com.chinairi.common.utils.UserSession;
import com.chinairi.mall.controller.viewobject.UserCompanyInfoVO;
import com.chinairi.mall.model.UserCompanyType;
import com.chinairi.mall.dao.UserCompanyTypeMapper;
import com.chinairi.mall.service.IUserCompanyTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Webgasd
 * @since 2020-09-25
 */
@Service
public class UserCompanyTypeServiceImpl extends ServiceImpl<UserCompanyTypeMapper, UserCompanyType> implements IUserCompanyTypeService {
    @Autowired
    private UserCompanyTypeMapper userCompanyTypeMapper;

    /**
     * 将资质类型int转换为名称
     * @param id 资质类型int
     * @return String
     */
    public String transformIdToName(int id){
        String name = "";
        if (id == 1) {
            name =  "供应商";
        }
        if (id == 2) {
            name = "服务商";
        }
        if (id == 3) {
            name = "采购商";
        }
        return name;
    }

    /**
     * 批量审核企业资质
     *
     * @param userCompanyTypeList
     */
    @Override
    public void batchUpdate(List<UserCompanyType> userCompanyTypeList) {
        if (userCompanyTypeList.size()>0){
            userCompanyTypeMapper.batchUpdate(userCompanyTypeList.stream().peek((list) -> {
                list.setCheckPerson(UserSession.getUserId());
                list.setCheckTime(new Date());
            }).collect(Collectors.toList()));
        }
    }
}
